package com.tiles.service.Impl;

import com.tiles.entity.TilesUser;
import com.tiles.mapper.TilesUserMapper;
import com.tiles.service.TilesUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service("tilesUserService")
public class TilesUserServiceImpl implements TilesUserService {

    @Autowired
    private TilesUserMapper userMapper;

    @Override
    public int selectByUserName(String username) {
        TilesUser tilesUser = new TilesUser();
        tilesUser.setTilesUsername(username);
        return userMapper.selectCount(tilesUser);

    }

    @Override
    public void insertTilesUser(TilesUser tilesUser) {
        userMapper.insertSelective(tilesUser);
    }

    @Override
    public int selectUserByNameAndPassword(String username, String password) {
        Example example = new Example(TilesUser.class);
        example.createCriteria()
                .andEqualTo("tilesUsername", username)
                .andEqualTo("tilesPassword", password);

        List<TilesUser> userList =  userMapper.selectByExample(example);
        ;
        return userMapper.selectCountByExample(example);
    }

    @Override
    public List<TilesUser> selectUserAll() {
        return userMapper.selectAll();
    }

    @Override
    public void updateToken(TilesUser tilesUser) {
        userMapper.updateByPrimaryKeySelective(tilesUser);
    }

    @Override
    public int selectUserEmail(String email) {
        TilesUser tilesUser = new TilesUser();
        tilesUser.setEmail(email);
        int i = userMapper.selectCount(tilesUser);
        return i;
    }
}
